@extends('admin::layouts.admin')
@section("main-content")
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-widget">
                <!-- /.box-header -->
                <div class="box-body">
                    <div class="row">
                        <div class="col-sm-12" id="me-table-search-form-example2"></div>
                        <div class="col-sm-12">
                            <table id="example2" class="table table-bordered table-hover"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
@include('admin::common.datatable')
@push("script")
    <script>
        var arrStatus = {1: "启用", 2: "禁用"},
            arrTypes = {
                1: "gitee",
                2: "github",
                3: "codding"
            },
            arrColors = {"1": "label-success", "2": "label-danger"};

        $(function () {
            $("#example2").MeTables({
                table: {
                    columns: [
                        {
                            title: "ID",
                            data: "id",
                            defaultOrder: "asc",
                            edit: {type: "hidden"}
                        },
                        {
                            title: "项目名称",
                            data: "name",
                            sortable: false,
                            search: {name: "name:like"},
                            edit: {
                                required: "true",
                                rangelength: "[2, 50]"
                            }
                        },
                        {
                            title: "项目说明",
                            data: "description",
                            sortable: false,
                            search: {name: "description:like"},
                            edit: {
                                required: "true",
                                rangelength: "[2, 100]"
                            }
                        },
                        {
                            title: "执行命令",
                            data: "command",
                            sortable: false,
                            edit: {
                                rangelength: "[2, 100]"
                            }
                        },
                        {
                            title: "密码",
                            data: "password",
                            sortable: false,
                            hide: true,
                            edit: {
                                required: true,
                                rangelength: "[2, 100]"
                            }
                        },
                        {
                            title: "Token",
                            data: "token",
                            sortable: false,
                            hide: true,
                            edit: {
                                required: true,
                                rangelength: "[2, 100]"
                            }
                        },
                        {
                            title: "地址",
                            data: null,
                            hide: true,
                            name: "url",
                            createdCell: function (td, data, row) {
                                $(td).html("{{ url('web-hooks/index')  }}?project=" + getValue(row, "name") + "&token=" + getValue(row, "token"));
                            }
                        },
                        {
                            title: "项目类型",
                            data: "type",
                            sortable: false,
                            value: arrTypes,
                            "render": function (data) {
                                return getValue(arrTypes, data);
                            },
                            edit: {
                                required: true, number: true, type: "select"
                            }
                        },
                        {
                            title: "允许IP",
                            data: "allow_ips",
                            sortable: false,
                            edit: {
                                required: true, rangelength: "[2, 200]"
                            }
                        },
                        {
                            title: "状态",
                            data: "status",
                            sortable: false,
                            render: function (data) {
                                return '<span class="label ' + getValue(arrColors, data, 'label-info') + '">' + getValue(arrStatus, data, data) + '</span>';
                            },
                            value: arrStatus,
                            edit: {
                                type: "radio",
                                default: 1,
                                required: true,
                                number: true
                            }
                        },
                        {title: "创建时间", data: "created_at", className: 'text-center',},
                        {title: "修改时间", data: "updated_at", className: 'text-center',},
                    ]
                }
            });
        })
    </script>
@endpush